package design.wlb.java_reading.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import design.wlb.java_reading.entity.GuaSixtyFour;
import design.wlb.java_reading.service.GuaSixtyFourService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wlb
 * @since 2025-09-10
 */
@RestController
@RequestMapping("/java_reading/gua_sixty_four")
public class GuaSixtyFourController {
    @Autowired
    GuaSixtyFourService guaSixtyFourService;

    @GetMapping(value = "/list")
    public List<GuaSixtyFour> getInfo(){
        return guaSixtyFourService.list();
    }

    @GetMapping("/page")
    public IPage<GuaSixtyFour> getPage(@RequestParam(defaultValue = "1") Integer current,
                                       @RequestParam(defaultValue = "10") Integer size,
                                       @RequestParam(required = false) String name) { // 可选查询参数
        // 组装查询条件
        Map<String, Object> condition = new HashMap<>();
        if (name != null && !name.trim().isEmpty()) {
            condition.put("name", name.trim());
        }

        // 调用 Service 方法
        return guaSixtyFourService.queryByPage(current, size, condition);
    }
}
